#include <REGX52.H>
#include "Delayxms.h"
#include "LCD1602.h"
#include "MatrixKey.h"

void VerifyPassword();

unsigned char KeyNUM = 0;
unsigned int OriginPassword = 8888;//初始密码
unsigned int password,count = 0;
//count用于密码数字计数

void main(){
	VerifyPassword();

}

void VerifyPassword(){
	LCD_Init();
	LCD_ShowString(1,1,"Password:");
	
	while(1){	

	KeyNUM = MatrixKey();
	//输入数字
	if(KeyNUM){
		if(KeyNUM <= 10){//如果S1-S10按键按下,输入密码
			if(count <4){
				password *= 10;//初始的password == 0
				password += KeyNUM % 10;//数字的移位操作
				count++;
			}
		}	
		if(KeyNUM == 12){
			if(password == OriginPassword){
				LCD_ShowString(1,14,"OK!");
				Delayxms(1500);
				LCD_ShowString(2,4,"   ");
				count = 0;
				password = 0;
				LCD_ShowString(2,10,"      ");
				LCD_ShowString(2,4,"    ");
				/*
				这里加入解锁的设备的开启引脚
				
				*/

			}else{
				LCD_ShowString(2,10,"ERROR!");
				count = 0;
				password = 0;
				Delayxms(1500);
				LCD_ShowString(2,10,"      ");
				LCD_ShowString(2,4,"    ");
			}
		}
		if(KeyNUM == 11){
			count = 0;
			password = 0;
			LCD_ShowNum(2,1,password,4);
		
		}
	LCD_ShowNum(2,1,password,4);
	}
	
	
	}

}
